package com.shuoyue.ycgk.ui.course.info;

import android.content.Context;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.OnScrollListener;

import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.entity.course_teacher.Teacher;
import com.shuoyue.ycgk.ui.course.adapter.TeacherAdapter;
import com.shuoyue.ycgk.utils.SizeUtil;
import com.shuoyue.ycgk.utils.SpacesItemDecoration;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class FragmentCourseTeacher extends BaseCourseInfoFragment {

    @BindView(R.id.list)
    RecyclerView list;
    ArrayList<Teacher> teachers;
    public static FragmentCourseTeacher newInstance(ArrayList<Teacher> teachers) {
        FragmentCourseTeacher fragment = new FragmentCourseTeacher();
        Bundle args = new Bundle();
        args.putSerializable("data", teachers);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void initParams(Bundle bundle) {
        teachers = (ArrayList<Teacher>) bundle.getSerializable("data");

    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_course_timetable;
    }

    @Override
    protected void initView() {
        list.setLayoutManager(new LinearLayoutManager(mContext));
        list.addItemDecoration(new SpacesItemDecoration(SizeUtil.dip2px(mContext, 8)));
        list.addOnScrollListener(new OnScrollListener() {
            @Override
            public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                if (dy == 0) {
                    isScrollAtTop = true;
                } else {
                    isScrollAtTop = false;
                }
            }

        });
    }

    @Override
    protected void initData() {
        setTeacher(teachers);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }


    void setTeacher(List<Teacher> teacher) {
        TeacherAdapter teacherAdapter = new TeacherAdapter(teacher);
        list.setAdapter(teacherAdapter);
    }

    @Override
    public String getTitle() {
        return "授课老师";
    }
}
